<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>05.form_fields | KnockOut</title>
  <script src="../assets/knockout-3.5.1.js"></script>
</head>
<body>

  <p>性别: <input type="checkbox" data-bind="checked: showGender" /></p>
  <div data-bind="visible: showGender">
    <div><input type="radio" name="gender" value="male" data-bind="checked: selectedGender" /> 先生</div>
    <div><input type="radio" name="gender" value="female" data-bind="checked: selectedGender" /> 女士</div>
    <div><input type="radio" name="gender" value="unknown" data-bind="checked: selectedGender" /> 未知</div>
  </div>
  
  <script type="text/javascript">
    var vm = {
      showGender: ko.observable(true),
      selectedGender: ko.observable("male") // 初始化默认选中项
    };

    // 后期修改
    // vm.selectedGender("unknown");

    ko.applyBindings(vm);
  </script>

</body>
</html>
